<template>
  <div>
    <el-form
      class="mt20 ml20"
      :model="queryParams"
      ref="queryForm"
      size="mini"
      label-width="68px"
    >
      <el-row :gutter="20">
        <el-col :span="5">
          <el-form-item label="资产类别" prop="assetTypeId">
            <treeselect
              class="treeselect-mini"
              append-to-body
              v-model="queryParams.assetTypeId"
              :options="options"
              :normalizer="normalizer"
              placeholder="类别"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="资产名称" prop="name">
            <el-input v-model="queryParams.name" placeholder="名称"> </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="规格型号" prop="model">
            <el-input v-model="queryParams.model" placeholder="规格型号">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label-width="0">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="getList"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-card>
      <div slot="header" class="clearfix">
        <span>固定资产台账汇总</span>
      </div>
      <el-table v-loading="loading" :data="list" row-key="id">
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column
          prop="assetTypeName"
          label="类别"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="model"
          label="规格型号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="unit"
          label="单位"
          align="center"
        ></el-table-column>
        <el-table-column prop="unusedNumber" label="未使用数量" align="center"
          ><template slot-scope="scope">
            <el-link
              type="info"
              :underline="false"
              @click="toList(scope.row, ['未使用'])"
              >{{ scope.row.unusedNumber }}</el-link
            >
          </template>
        </el-table-column>
        <el-table-column prop="useNumber" label="使用中数量" align="center"
          ><template slot-scope="scope">
            <el-link
              type="info"
              :underline="false"
              @click="toList(scope.row, ['使用中'])"
              >{{ scope.row.useNumber }}</el-link
            >
          </template>
        </el-table-column>
        <el-table-column prop="repairNumber" label="维修中数量" align="center"
          ><template slot-scope="scope">
            <el-link
              type="info"
              :underline="false"
              @click="toList(scope.row, ['维修中'])"
              >{{ scope.row.repairNumber }}</el-link
            >
          </template>
        </el-table-column>
        <el-table-column prop="scrapNumber" label="报废数量" align="center"
          ><template slot-scope="scope">
            <el-link
              type="info"
              :underline="false"
              @click="toList(scope.row, ['报废'])"
              >{{ scope.row.scrapNumber }}</el-link
            >
          </template>
        </el-table-column>
        <el-table-column prop="total" label="总数" align="center">
          <template slot-scope="scope">
            <el-link
              type="info"
              :underline="false"
              @click="toList(scope.row)"
              >{{ scope.row.total }}</el-link
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="queryParams.total > 0"
        :total="queryParams.total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { summary } from "@/api/prod/asset/account";
import { pageList as option } from "@/api/prod/purchase/asset-type";
import { handleOptions } from "@/utils/base/options";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "BaseLog",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表格数据
      list: [],
      // 请求参数
      queryParams: {
        assetTypeId: null,
        name: null,
        model: null,

        pageNum: 1,
        pageSize: 10,
        // 总数
        total: 0,
      },
      // 选项
      options: [],
    };
  },
  created() {
    // 资产类别
    option({}).then((response) => {
      this.options = handleOptions(response.data);
    });

    this.getList();
  },

  methods: {
    /** 转换资产类别数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },

    /** 重置按钮事件 */
    resetQuery() {
      this.queryParams.assetTypeId = null;
      this.queryParams.name = null;
      this.queryParams.model = null;
    },

    /** 查询采购进程列表 */
    getList() {
      this.loading = true;
      summary(this.queryParams).then((response) => {
        this.list = response.data;
        this.queryParams.total = response.info.total;
        this.loading = false;
      });
    },

    /** 跳转到列表页 */
    toList(row, assetStateList) {
      this.$router.push({
        path: "/asset/asset/account/list",
        query: {
          assetTypeId: row.assetTypeId,
          name: row.name,
          model: row.model,
          assetStateList,
        },
      });
    },
  },
};
</script>

<style>
</style>